package org.rooster.manager;

import org.rooster.dbmanager.repository.RoosterRepository;
import org.rooster.schedule.ManagerPreference;

import java.util.Iterator;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: manorama
 * Date: 7/22/12
 * Time: 10:56 AM
 * To change this template use File | Settings | File Templates.
 */
public class ManagerPreferencesTracker {

    private static ManagerPreferencesTracker instance;
    private int[][] managerPreferences;

    private ManagerPreferencesTracker(){
        managerPreferences = new int[TaskManager.NO_OF_SECTIONS][ResourceManager.TOTAL_NO_OF_EMPLOYEES];
        initializeManagerPreferencesTracker();
    }

    public static ManagerPreferencesTracker getInstance() {
        if(instance == null) {
            instance = new ManagerPreferencesTracker();
        }
        return instance;
    }

    private void initializeManagerPreferencesTracker() {
        Set<ManagerPreference> managerPreferenceSet = RoosterRepository.getInstance().retrieveManagerPreferencesSet();

        //todo retrieve the number of tasks using the count SQl statements

        Iterator iterator = managerPreferenceSet.iterator();
        ManagerPreference managerPreference;
        while (iterator.hasNext()) {
            managerPreference = (ManagerPreference) iterator.next();
            managerPreferences[managerPreference.getTaskId()]
                    [managerPreference.getResourceId()]= managerPreference.getPreference();
        }
    }

    public int getManagerPreference(int sectionNo, int employeeId) {
        return managerPreferences[sectionNo-1][employeeId-1];
    }

}
